import java.util.Vector;

public class OpeningMoves {

	/**
	 * If the GameLogic is the starting player, this tests to see if it can beat
	 * the opponent with the opening moves.
	 * 
	 * Similar if it is second player, it tests to avoid losing within the first
	 * moves.
	 * 
	 * If a correct column is found, this is returned otherwise -2 is returned,
	 * which causes the opening moves to end and the heuristic to start.
	 * 
	 * @param plies
	 * @param movesFirst
	 * @return
	 */
	public int testPly(Vector plies, boolean movesFirst) {
		int column = -2;
		if (movesFirst) {
			switch (plies.size()) {
			case 0:
				column = 3;
				break;
			case 2:
				if (plies.toString().equals("[3, 0]"))	column = 4;
				else if (plies.toString().equals("[3, 1]"))	column = 4;
				else if (plies.toString().equals("[3, 3]"))	column = 2;
				else if (plies.toString().equals("[3, 5]"))	column = 2;
				else if (plies.toString().equals("[3, 6]"))	column = 2;
				else column = -2;
				break;
			case 4:
				if (plies.toString().equals("[3, 0, 4, 0]")) column = 2;
				else if (plies.toString().equals("[3, 0, 4, 1]")) column = 5;
				else if (plies.toString().equals("[3, 0, 4, 3]")) column = 2;
				else if (plies.toString().equals("[3, 0, 4, 4]")) column = 2;
				else if (plies.toString().equals("[3, 0, 4, 6]")) column = 2;
				
				else if (plies.toString().equals("[3, 1, 4, 0]")) column = 5;
				else if (plies.toString().equals("[3, 1, 4, 1]")) column = 5;
				else if (plies.toString().equals("[3, 1, 4, 3]")) column = 5;
				else if (plies.toString().equals("[3, 1, 4, 4]")) column = 5;
				
				else if (plies.toString().equals("[3, 3, 2, 0]")) column = 4;
				else if (plies.toString().equals("[3, 3, 2, 2]")) column = 4;
				else if (plies.toString().equals("[3, 3, 2, 3]")) column = 4;
				else if (plies.toString().equals("[3, 3, 2, 5]")) column = 1;
				else if (plies.toString().equals("[3, 3, 2, 6]")) column = 4;
				
				else if (plies.toString().equals("[3, 5, 2, 2]")) column = 1;
				else if (plies.toString().equals("[3, 5, 2, 3]")) column = 1;
				else if (plies.toString().equals("[3, 5, 2, 5]")) column = 1;
				else if (plies.toString().equals("[3, 5, 2, 6]")) column = 1;
				
				else if (plies.toString().equals("[3, 6, 2, 0]")) column = 4;
				else if (plies.toString().equals("[3, 6, 2, 2]")) column = 4;
				else if (plies.toString().equals("[3, 6, 2, 3]")) column = 4;
				else if (plies.toString().equals("[3, 6, 2, 5]")) column = 1;
				else if (plies.toString().equals("[3, 6, 2, 6]")) column = 4;
				else column = -2;
				break;
			default:
				column = -2;
				break;
			}
		} else {	//Counter measures :)
			switch (plies.size()) {
			case 1:
				column = 3;
				break;
			case 3:
				if (plies.toString().equals("[3, 3, 0]"))	column = 2;
				else if (plies.toString().equals("[3, 3, 1]"))	column = 2;
				else if (plies.toString().equals("[3, 3, 2]"))	column = 4;
				else if (plies.toString().equals("[3, 3, 3]"))	column = 2;
				else if (plies.toString().equals("[3, 3, 4]"))	column = 2;
				else if (plies.toString().equals("[3, 3, 5]"))	column = 4;
				else if (plies.toString().equals("[3, 3, 6]"))	column = 4;
				break;
			case 5:
				if (plies.toString().equals("[3, 3, 2, 4, 0]"))			column = 1;
				else if (plies.toString().equals("[3, 3, 2, 4, 1]"))	column = 0;
				else if (plies.toString().equals("[3, 3, 2, 4, 2]"))	column = 2;	//Could be omitted
				else if (plies.toString().equals("[3, 3, 4, 2, 4]"))	column = 4;
				else if (plies.toString().equals("[3, 3, 4, 2, 5]"))	column = 6;
				else if (plies.toString().equals("[3, 3, 4, 2, 6]"))	column = 5;
				break;
			default:
				column = -2;
				break;
			}
		}
		return column;
	}
}
